/*
	file:   tword.h
	author: Anders Ma
	email:  xuejiao.ma@gmail.com
	date:   2010_1118
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdarg.h>
#include <expat.h>
#include <signal.h>

#include "date.h"

#ifndef _WIN32
#include <termios.h>
#endif

#ifdef _WIN32
#include <windows.h>
#else
#include <sys/time.h>
#endif

#if defined(__amigaos__) && defined(__USE_INLINE__)
#include <proto/expat.h>
#endif

#ifdef XML_LARGE_SIZE
#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400
#define XML_FMT_INT_MOD "I64"
#else
#define XML_FMT_INT_MOD "ll"
#endif
#else
#define XML_FMT_INT_MOD "l"
#endif

#define VERSION_MAJOR 1
#define VERSION_MINOR 1

/*
	be careful, don't use any break condition algorithm in PRINT
	just to prevert infinite loop
*/

#ifdef _WIN32
#define DEBUG_PRINT1 
#endif

#ifdef DEBUG_PRINT_ALL
#define DEBUG_PRINT0
#define DEBUG_PRINT1
#endif

#ifdef DEBUG_PRINT0 
#define PRINT0  printf
#else
#define PRINT0(...) do {} while (0)
#endif

#ifdef DEBUG_PRINT1 
#define PRINT1  printf
#else
#define PRINT1(...) do {} while (0)
#endif

#define DEF_WORD_FILE_NAME "toefl.xml"
#define MAX_BUFLINE_SIZE 10240
#define MAX_FILE_NAME_SIZE 100

// tag string
#define TAG_CLASS "class"
#define TAG_SUBCLASS "subclass"
#define TAG_WORD "word"
#define TAG_SLOT "slot"
#define TAG_EXAMPLE "example"
// attribute string
#define ATTR_NAME "name"
#define ATTR_TYPE "type"
#define ATTR_LANG "lang"
#define ATTR_MEAN "mean"
// word/language type string
#define STR_WORD_NOUN "n."
#define STR_WORD_VERB "v."
#define STR_WORD_VI "vi."
#define STR_WORD_VT "vt."
#define STR_WORD_ADJ "adj."
#define STR_WORD_ADV "adv."
#define STR_LANG_EN "en"
#define STR_LANG_CN "cn"
// word testing parameters
#define RANDOM_TEST_BATCH_OUTPUT_NO 5

typedef enum _NODE_TYPE {
	UNKNOWN_NODE = 0,
	WORD_NODE,
	SLOT_NODE,
	EXAMPLE_NODE
} NODE_TYPE;

typedef enum _WORD_LANG_ {
	UNKNOWN_LANG = 0,
	LANG_EN,
	LANG_CN
} WORD_LANG;

typedef enum _WORD_TYPE {
	WORD_UNKNOWN = 0,
	WORD_NOUN,
	WORD_VERB,
	WORD_VI,
	WORD_VT,
	WORD_ADJ,
	WORD_ADV
} WORD_TYPE;

typedef struct _slot_t {
	WORD_TYPE type;
	WORD_LANG lang;
	char *mean;
	char *example;
	struct _slot_t *next;
} slot_t;

typedef struct _word_t {
	char *class; 
	char *name;
	WORD_LANG lang;
	unsigned int hit; /*hit counter during test, to keep balance*/
	slot_t *slot_list;
	struct _word_t *next;
} word_t;

extern word_t *g_word_head;
extern int g_word_counter;
extern void DBG_PRINT(const char *msg, ...);
extern char* get_word_type_str(WORD_TYPE type);

#define WORD_HEAD (g_word_head)
#define WORD_TAIL (g_word_tail)
#define SLOT (g_word_tail->slot_list)
#define EXAMPLE (g_word_head->slot_list->example)

#define SET_WORD_HEAD(x) do { g_word_head=x; } while (0)
#define GET_WORD_CTR() g_word_counter
#define INC_WORD_cTR() ++g_word_counter


